package user.zc.action.comp;

import javax.swing.*;
import java.awt.*;
import java.util.Optional;

public class IComboBox extends JComboBox implements IField{
    private String label;
    private String defaultValue;
    public IComboBox(String[] selects,String label,Integer width){
        super(selects);
        this.label = label;
        setPreferredSize(new Dimension(width, 25));// 这里就是设置JComboBox宽度的代码
    }
    public IComboBox(String[] selects,String label,Integer width,String name){
        this(selects,label,width);
        setName(name);
    }
    public IComboBox(String[] selects,String label,Integer width,String name,String defaultText){
        this(selects,label,width);
        this.setSelectedItem(defaultText);
        this.defaultValue = defaultText;
    }

    @Override
    public String getLabel() {
        return this.label;
    }

    @Override
    public String getText() {
        return Optional.ofNullable(getSelectedItem()).orElse("").toString();
    }

    @Override
    public String getDefaultValue() {
        return this.defaultValue;
    }
}
